<template>
  <!-- 根据路由判断使用哪种布局 -->
  <div class="app-container">
    <template v-if="isAdminRoute">
      <!-- 管理界面布局 -->
      <el-container>
        <el-header>
          <div class="admin-header">
            <h2>商品管理系统</h2>
            <el-button type="danger" @click="handleLogout">退出登录</el-button>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </template>
    <template v-else>
      <!-- 普通用户界面布局 -->
      <router-view></router-view>
    </template>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import 'element-plus/dist/index.css'
import router from "@/router";

const route = useRoute()

// 判断是否是管理界面路由
const isAdminRoute = computed(() => {
  return route.path.includes('/admin') && !route.path.includes('/admin/login')
})

// 退出登录
const handleLogout = () => {
  localStorage.removeItem('token')
  router.push("/")
}
</script>

<style>
/* 重置默认样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  width: 100%;
}

#app {
  height: 100%;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 添加管理界面相关样式 */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.el-header {
  padding: 0;
  height: 60px;
  line-height: 60px;
  background-color: #fff;
}

.el-main {
  background-color: #f5f5f5;
  padding: 20px;
}

/* Element Plus 容器组件样式覆盖 */
.el-container {
  height: 100%;
}

.el-aside {
  background-color: #304156;
  color: #fff;
}

.el-menu {
  border-right: none;
  background-color: transparent;
}

.el-menu-item, .el-sub-menu__title {
  color: #fff;
}

.el-menu-item:hover, .el-sub-menu__title:hover {
  background-color: #263445;
}

.el-menu-item.is-active {
  background-color: #1890ff;
}

/* 添加一些基础样式 */
.app-container {
  height: 100vh;
  width: 100vw;
}
</style>
